// ignore_for_file: file_names, slash_for_doc_comments, must_call_super, unnecessary_overrides, override_on_non_overriding_member, must_be_immutable, prefer_const_constructors

import 'package:flutter/material.dart';
import 'package:mybase/base/abstract/IFFR.dart';
import 'package:mybase/base/abstract/IFFRefresh.dart';
import 'package:mybase/base/abstract/IFFScaffold.dart';
import 'package:mybase/base/super/FFInk.dart';
import 'package:mybase/base/tool/arouter/FFGoto.dart';
import 'package:mybase/base/tool/file/FFDirectory.dart';
import 'package:mybase/base/widget/layout/FFTextButton.dart';
import 'package:mybase/base/widget/page/FFListScaffold.dart';
import 'package:mybase/base/tool/extension/FFListExt.dart';
import 'package:webview_window_example/config/ConfigVal.dart';
import 'package:webview_window_example/pages/androidUpdateXml/AndroidUpdateXmlPage.dart';
import 'package:webview_window_example/pages/appin/AppInTranslatePage.dart';
import 'package:webview_window_example/pages/appleUpdateTxt/AppleUpdateTxtPage.dart';
import 'package:webview_window_example/pages/completeLanguageJson/CompleteLanguageJsonPage.dart';
import 'package:webview_window_example/pages/createApi/CreateApiPage.dart';
import 'package:webview_window_example/pages/createTemplateCode/CreateTemplateCodePage.dart';
import 'package:webview_window_example/pages/englishChinese/EnglishChinesePage.dart';
import 'package:webview_window_example/pages/jsonToEntity/JsonToEntityPage.dart';
import 'package:webview_window_example/utils/navi/AppNavi.dart';
import 'package:webview_window_example/main.dart';

class MainPage extends FFListScaffold {
  String? name;

  MainPage({
    Key? key,
    this.name,
  }) : super(key: key);

  @override
  MainPageState createState() => MainPageState();
}

class MainPageState extends FFListScaffoldState {
  /**固定写法 */
  @override
  IFFScaffold get iffScaffold => this;

  @override
  MainPage get widget => super.widget as MainPage;

  ///刷新控制
  @override
  IFFRefresh? get iffRefresh => refresh;
  late MainPageStateRefresh refresh = MainPageStateRefresh(state: this);

  @override
  FFPageSpacingParam? get ffPageSpacingParam =>
      FFPageSpacingParam(bottomSpacing: true);

  /**固定写法end */

  @override
  void ffInitState() {
    super.ffInitState();
  }

  @override
  Widget? ffNavi(BuildContext context) {
    return AppNavi.createNavi(
      context,
      leadingHidden: true,
      title: "功能首页",
    );
  }

  @override
  Widget ffItem(BuildContext context, int index) {
    MainEntity entity = datas[index];
    return FFInk(
      child: FFTextButton(
        text: entity.title,
        fontSize: 16,
        heigth: 60,
        decoration: BoxDecoration(
          color: Colors.grey.withAlpha(50),
        ),
        margin: EdgeInsets.only(bottom: 2),
        onClick: entity.onClick,
        padding: EdgeInsets.all(8),
      ),
    );
  }
}

class MainPageStateRefresh with MFFRefresh {
  MainPageState state;

  MainPageStateRefresh({required this.state});

  @override
  bool? ffCanRefreshHead() {
    return false;
  }

  @override
  bool? ffCanRefreshFoot() {
    return false;
  }

  @override
  ffRefresh(bool isHead) {
    ffRefreshResult(isHead, test, state);
  }

  Future<IFFR> test(IRefreshParam? iRefreshParam) async {
    if (!(await FFDirectory.isExistDirectory(ConfigVal.osDir))) {
      ConfigVal.reassignToTootDirectory();
    }

    List<MainEntity> list = [
      MainEntity(
          title: "中英互译",
          onClick: () {
            FFGoto.gotoPage(navigatorKey.currentContext!, EnglishChinesePage());
          }),
      MainEntity(
          title: "1.以zh-Hans.json为基础补全其他json缺失的key",
          onClick: () {
            FFGoto.gotoPage(
                navigatorKey.currentContext!, CompleteLanguageJsonPage());
          }),
      MainEntity(
          title: "2.flutter项目内翻译",
          onClick: () {
            FFGoto.gotoPage(navigatorKey.currentContext!, AppInTranslatePage());
          }),
      MainEntity(
          title: "Android xml更新翻译",
          onClick: () {
            FFGoto.gotoPage(
                navigatorKey.currentContext!, AndroidUpdateXmlPage());
          }),
      MainEntity(
          title: "ios版本更新翻译",
          onClick: () {
            FFGoto.gotoPage(navigatorKey.currentContext!, AppleUpdateTxtPage());
          }),
      MainEntity(
          title: "生成模板代码",
          onClick: () {
            FFGoto.gotoPage(
                navigatorKey.currentContext!, CreateTemplateCodePage());
          }),
      MainEntity(
          title: "生成api调用方法",
          onClick: () {
            FFGoto.gotoPage(navigatorKey.currentContext!, CreateApiPage());
          }),
      MainEntity(
          title: "json生成实体类",
          onClick: () {
            FFGoto.gotoPage(navigatorKey.currentContext!, JsonToEntityPage());
          }),
    ];

    return R(rStatus: RStatus.result, data: list);
  }
}
